using System;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Logic;
using NetProtocol.POD;

namespace IQIGame.Onigao.GamePlay
{
    public partial class BattleRenderQueueController
    {
        private bool TryParseUpdate(BattleUpdatePOD rPOD, out IBaseBattleCommandView rCommandView)
        {
            rCommandView = null;
            if (rPOD == null)
            {
                return false;
            }
            switch ((EBattleUpdateType)rPOD.type)
            {
                case EBattleUpdateType.StartPart:
                {
                    var rCommand = rPOD.data as BattleCommand_StartPart;
                    var rView = ClassPool.Get<BattleCommandView_StartPart>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.SkillEffective:
                {
                    var rCommand = rPOD.data as BattleCommand_SkillEffective;
                    var rView = ClassPool.Get<BattleCommandView_SkillEffective>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.BuffChange:
                {
                    var rCommand = rPOD.data as BattleCommand_BuffChange;
                    var rView = ClassPool.Get<BattleCommandView_BuffChange>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.AttrChange:
                {
                    var rCommand = rPOD.data as BattleCommand_AttrChange;
                    var rView = ClassPool.Get<BattleCommandView_AttrChange>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.PosChange:
                {
                    var rCommand = rPOD.data as BattleCommand_PosChange;
                    var rView = ClassPool.Get<BattleCommandView_PosChange>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.Dead:
                {
                    var rCommand = rPOD.data as BattleCommand_Dead;
                    var rView = ClassPool.Get<BattleCommandView_Dead>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.BuffDamage:
                {
                    var rCommand = rPOD.data as BattleCommand_BuffDamage;
                    var rView = ClassPool.Get<BattleCommandView_BuffDamage>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.Shield:
                {
                    var rCommand = rPOD.data as BattleCommand_Shield;
                    var rView = ClassPool.Get<BattleCommandView_Shield>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.CustomProperty:
                {
                    var rCommand = rPOD.data as BattleCommand_CustomProperty;
                    var rView = ClassPool.Get<BattleCommandView_CustomProperty>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.BuffCure:
                {
                    var rCommand = rPOD.data as BattleCommand_BuffCure;
                    var rView = ClassPool.Get<BattleCommandView_BuffCure>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.AddSkill:
                {
                    var rCommand = rPOD.data as BattleCommand_AddSkill;
                    var rView = ClassPool.Get<BattleCommandView_AddSkill>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.WeaknessPoint:
                {
                    var rCommand = rPOD.data as BattleCommand_WeaknessPoint;
                    var rView = ClassPool.Get<BattleCommandView_WeaknessPoint>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.SkillEffectiveStart:
                {
                    var rCommand = rPOD.data as BattleCommand_SkillEffectiveStart;
                    var rView = ClassPool.Get<BattleCommandView_SkillEffectiveStart>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.SkillEffectiveEnd:
                {
                    var rCommand = rPOD.data as BattleCommand_SkillEffectiveEnd;
                    var rView = ClassPool.Get<BattleCommandView_SkillEffectiveEnd>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.Charge:
                {
                    var rCommand = rPOD.data as BattleCommand_Charge;
                    var rView = ClassPool.Get<BattleCommandView_Charge>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.ChargeStop:
                {
                    var rCommand = rPOD.data as BattleCommand_ChargeStop;
                    var rView = ClassPool.Get<BattleCommandView_ChargeStop>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.Morph:
                {
                    var rCommand = rPOD.data as BattleCommand_Morph;
                    var rView = ClassPool.Get<BattleCommandView_Morph>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.Round:
                {
                    var rCommand = rPOD.data as BattleCommand_Round;
                    var rView = ClassPool.Get<BattleCommandView_Round>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.Turn:
                {
                    var rCommand = rPOD.data as BattleCommand_Turn;
                    var rView = ClassPool.Get<BattleCommandView_Turn>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.PermitCast:
                {
                    var rCommand = rPOD.data as BattleCommand_PermitCast;
                    var rView = ClassPool.Get<BattleCommandView_PermitCast>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.CastSkill:
                {
                    var rCommand = rPOD.data as BattleCommand_CastSkill;
                    var rView = ClassPool.Get<BattleCommandView_CastSkill>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.CastSkillComplete:
                {
                    var rCommand = rPOD.data as BattleCommand_CastSkillComplete;
                    var rView = ClassPool.Get<BattleCommandView_CastSkillComplete>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.Substitute:
                {
                    var rCommand = rPOD.data as BattleCommand_Substitute;
                    var rView = ClassPool.Get<BattleCommandView_Substitute>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.NextWave:
                {
                    var rCommand = rPOD.data as BattleCommand_NextWave;
                    var rView = ClassPool.Get<BattleCommandView_NextWave>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.SkillEffectiveResponse:
                {
                    var rCommand = rPOD.data as BattleCommand_SkillEffectiveResponse;
                    var rView = ClassPool.Get<BattleCommandView_SkillEffectiveResponse>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                case EBattleUpdateType.RemoveUnit:
                {
                    var rCommand = rPOD.data as BattleCommand_RemoveUnit;
                    var rView = ClassPool.Get<BattleCommandView_RemoveUnit>();
                    rView.Initialize(rCommand, rPOD.executerId, this._cancel);
                    rCommandView = rView;
                    break;
                }
                default:
                    throw new Exception($"在尝试解析未指定的BattleCommand:{(EBattleUpdateType)rPOD.type}");
            }
            return rCommandView != null;
        }
    }
}
